package com.hui.service.impl;

import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.IdUtil;
import cn.hutool.core.util.NumberUtil;
import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.StrUtil;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.hui.constant.OrderConstants;
import com.hui.entity.dao.*;
import com.hui.entity.dto.CacheDto;
import com.hui.entity.dto.OtherDto;
import com.hui.entity.dto.PriceGroupDto;
import com.hui.entity.dto.StatusDto;
import com.hui.entity.enums.*;
import com.hui.entity.event.TemplateBean;
import com.hui.entity.event.TemplateEvent;
import com.hui.entity.vo.*;
import com.hui.handler.exception.SystemException;
import com.hui.mapper.StoreCartMapper;
import com.hui.mapper.StoreOrderMapper;
import com.hui.model.order.OrderParam;
import com.hui.service.*;
import com.hui.util.BeanCopyUtils;
import com.hui.util.RedisUtils;
import com.hui.util.ResponseResult;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationEventPublisher;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;

import java.math.BigDecimal;
import java.util.*;
import java.util.concurrent.TimeUnit;
import java.util.stream.Collectors;

/**
 * 订单表(StoreOrder)表服务实现类
 *
 * @author hui
 * @since 2022-07-21 00:12:56
 */
@Slf4j
@RequiredArgsConstructor
@Service("storeOrderService")
// TODO 整个文件了解
public class StoreOrderServiceImpl extends ServiceImpl<StoreOrderMapper, StoreOrder> implements StoreOrderService {

    private final StoreCartService storeCartService;
    private final SystemConfigService systemConfigService;//配置表
    private final UserService userService;//用户信息
    private final RedisUtils redisUtils;//redis工具类
    private final StoreProductService productService;
    private final StoreOrderCartInfoService orderCartInfoService;//购物订单详情表
    private final StoreCartMapper storeCartMapper; //购物车表
    private final StoreOrderStatusService orderStatusService;//
    private final StoreOrderMapper yxStoreOrderMapper;
    private final RedisTemplate<String, String> redisTemplate;
    private final UserBillService billService;
    private final ApplicationEventPublisher publisher;
    @Autowired
    private UserAddressService userAddressService; //地址信息

    /**
     * 准备创建订单
     *
     * @param shopUser
     * @param cartIds  购物车ID列表
     * @return
     */
    @Override
    public ResponseResult confirmOrder(ShopUser shopUser, List<Integer> cartIds) {
        //获取用户ID
        Long uid = shopUser.getUid();
        //获取提交的购物车ID列表的商品信息
        Map<String, Object> cartGroup = (Map<String, Object>) storeCartService.getUserProductCartList(uid, cartIds, 1).getData();
        //将商品信息进行效验
        if (ObjectUtil.isNotEmpty(cartGroup.get("invalid"))) {
            throw new SystemException(AppHttpCodeEnum.NO_PARAMETE_OPERATE.getCode(), "有失效的商品请重新提交");
        } else if (ObjectUtil.isEmpty(cartGroup.get("valid"))) {
            throw new SystemException(AppHttpCodeEnum.NO_PARAMETE_OPERATE.getCode(), "请提交购买的商品");
        } else {
            OtherDto other = new OtherDto();
            /*不知的到干啥的*/
            other.setIntegralRatio(this.systemConfigService.getData("integral_ratio"));
            other.setIntegralFull(this.systemConfigService.getData("integral_full"));
            other.setIntegralMax(this.systemConfigService.getData("integral_max"));
            /*不知的到干啥的*/
            Long combinationId = null;
            Long secKillId = null;
            Long bargainId = null;
            //只有一个商品
            if (cartIds.size() == 1) {
                StoreCart cartQueryVo = (StoreCart) this.storeCartService.getById(cartIds.get(0));
                combinationId = cartQueryVo.getCombinationId();
                secKillId = cartQueryVo.getSeckillId();
                bargainId = cartQueryVo.getBargainId();
            }

            boolean deduction = false;
            boolean enableIntegral = true;
            if (combinationId != null && combinationId > 0L || secKillId != null && secKillId > 0L || bargainId != null && bargainId > 0L) {
                deduction = true;
            }
            /*查询一条结果（没了解）*/
            LambdaQueryWrapper<UserAddress> wrapper = new LambdaQueryWrapper<>();
            wrapper.eq(UserAddress::getUid, uid)
                    .eq(UserAddress::getIsDefault, ShopCommonEnum.DEFAULT_1.getValue());
            UserAddress userAddress = this.userAddressService.getOne(wrapper, false);
            /*计算总价*/
            List<StoreCartQueryVo> cartInfo = (List) cartGroup.get("valid");
            //计算价格
            PriceGroupDto priceGroup = this.getOrderPriceGroup(cartInfo, userAddress);
            /*计算总价end*/
            if (priceGroup.getTotalPrice().compareTo(new BigDecimal(other.getIntegralFull())) < 0) {
                enableIntegral = false;
            }
            String cacheKey = this.cacheOrderInfo(uid, cartInfo, priceGroup, other);
            List<String> productIds = (List) cartInfo.stream().map(StoreCartQueryVo::getProductId).map(Object::toString).collect(Collectors.toList());

            //获取用户信息
            ShopUser userById = userService.getById(uid);
            EshopUserVo eshopUserVo = BeanCopyUtils.copyBean(userById, EshopUserVo.class);
            ConfirmOrderVo confirmOrderVo = ConfirmOrderVo.builder()
                    .addressInfo(userAddress)
                    .cartInfo(cartInfo).priceGroup(priceGroup)
                    .userInfo(eshopUserVo)
                    .orderKey(cacheKey)
                    .deduction(deduction)
                    .enableIntegral(enableIntegral)
                    .enableIntegralNum(Double.valueOf(other.getIntegralMax()))
                    .build();
            return ResponseResult.okResult(confirmOrderVo);
        }

    }


    @Override
    public StoreOrderQueryVo getOrderInfo(String unique, Long uid) {
        LambdaQueryWrapper<StoreOrder> wrapper = new LambdaQueryWrapper();
        wrapper.and((i) -> {
            LambdaQueryWrapper var10000 = i.eq(StoreOrder::getOrderId, unique)
                    .or().eq(StoreOrder::getUnique, unique)
                    .or().eq(StoreOrder::getExtendOrderId, unique);
        });
        if (uid != null) {
            wrapper.eq(StoreOrder::getUid, uid);
        }
        StoreOrder storeOrder = getOne(wrapper);
        StoreOrderQueryVo storeOrderQueryVo = null;
        if (ObjectUtil.isNotNull(storeOrder)) {
            storeOrderQueryVo = BeanCopyUtils.copyBean(storeOrder, StoreOrderQueryVo.class);
        }
        return storeOrderQueryVo;
    }

    /**
     * 创建订单
     *
     * @param
     * @param key
     * @param param
     * @return
     */
    @Override
    public StoreOrder createOrder(ShopUser userInfo, String key, OrderParam param) {
        ComputeVo computeVo = this.computedOrder(userInfo, key, param.getCouponId(), param.getUseIntegral(), param.getShippingType(), param.getAddressId());
        Long uid = userInfo.getUid();
        UserAddress userAddress = null;
        if (OrderInfoEnum.SHIPPIING_TYPE_1.getValue().equals(Integer.valueOf(param.getShippingType()))) {
            if (StrUtil.isEmpty(param.getAddressId())) {
                throw new SystemException(AppHttpCodeEnum.NO_PARAMETE_OPERATE.getCode(), "请选择收货地址");
            }

            userAddress = (UserAddress) this.userAddressService.getById(param.getAddressId());
            if (ObjectUtil.isNull(userAddress)) {
                throw new SystemException(AppHttpCodeEnum.NO_PARAMETE_OPERATE.getCode(), "地址选择有误");
            }
        } else {
            if (StrUtil.isBlank(param.getRealName()) || StrUtil.isBlank(param.getPhone())) {
                throw new SystemException(AppHttpCodeEnum.NO_PARAMETE_OPERATE.getCode(), "请填写姓名和电话");
            }

            userAddress = new UserAddress();
            userAddress.setRealName(param.getRealName());
            userAddress.setPhone(param.getPhone());
            userAddress.setProvince("");
            userAddress.setCity("");
            userAddress.setDistrict("");
            userAddress.setDetail("");
        }
        Integer totalNum = 0;
        List<String> cartIds = new ArrayList();
        Long combinationId = 0L;
        Long seckillId = 0L;
        Long bargainId = 0L;
        Boolean isIntegral = false;
        BigDecimal integral = BigDecimal.ZERO;
        CacheDto cacheDTO = this.getCacheOrderInfo(uid, key);
        List<StoreCartQueryVo> cartInfo = cacheDTO.getCartInfo();

        for (StoreCartQueryVo cart : cartInfo) {
            this.storeCartService.checkProductStock(uid, cart.getProductId(), cart.getCartNum(), cart.getProductAttrUnique(), cart.getCombinationId(), cart.getSeckillId(), cart.getBargainId());
            combinationId = cart.getCombinationId();
            seckillId = cart.getSeckillId();
            bargainId = cart.getBargainId();
            cartIds.add(cart.getId().toString());
            totalNum = totalNum + cart.getCartNum();
            if (cart.getProductInfo().getIsIntegral() != null && cart.getProductInfo().getIsIntegral() == 1) {
                integral = NumberUtil.add(integral, NumberUtil.mul(cart.getCartNum(), cart.getProductInfo().getAttrInfo().getIntegral()));
            }
        }
        //应该是积分有关
        BigDecimal gainIntegral = this.getGainIntegral(cartInfo);
        if (PayTypeEnum.INTEGRAL.getValue().equals(param.getPayType())) {
            gainIntegral = BigDecimal.ZERO;
            isIntegral = true;
        }

        String orderSn = IdUtil.getSnowflake(0L, 0L).nextIdStr();
        StoreOrder storeOrder = new StoreOrder();
        storeOrder.setUid(Long.valueOf(String.valueOf(uid)));
        storeOrder.setOrderId(orderSn);
        storeOrder.setRealName(userAddress.getRealName());
        storeOrder.setUserPhone(userAddress.getPhone());
        storeOrder.setUserAddress(userAddress.getProvince() + " " + userAddress.getCity() + " " + userAddress.getDistrict() + " " + userAddress.getDetail());
        storeOrder.setCartId(StrUtil.join(",", new Object[]{cartIds}));
        storeOrder.setTotalNum(Long.valueOf(totalNum));
        storeOrder.setTotalPrice(computeVo.getTotalPrice());
        storeOrder.setTotalPostage(computeVo.getPayPostage());
        storeOrder.setCouponId(Long.valueOf((param.getCouponId())));
        storeOrder.setCouponPrice(computeVo.getCouponPrice());
        storeOrder.setPayPrice(computeVo.getPayPrice());
        storeOrder.setPayPostage(computeVo.getPayPostage());
        storeOrder.setDeductionPrice(computeVo.getDeductionPrice());
        storeOrder.setPaid(OrderInfoEnum.PAY_STATUS_0.getValue());
        storeOrder.setPayType(param.getPayType());
        storeOrder.setCreateTime(new Date());
        if (isIntegral) {
            storeOrder.setPayIntegral(integral);
        }

        storeOrder.setUseIntegral(BigDecimal.valueOf(computeVo.getUsedIntegral()));
        storeOrder.setBackIntegral(BigDecimal.ZERO);
        storeOrder.setGainIntegral(gainIntegral);
        storeOrder.setMark(param.getMark());
        storeOrder.setCombinationId(combinationId);
        storeOrder.setPinkId(Long.valueOf(param.getPinkId()));
        storeOrder.setSeckillId(seckillId);
        storeOrder.setBargainId(bargainId);
        storeOrder.setCost(cacheDTO.getPriceGroup().getCostPrice());
        if (AppFromEnum.ROUNTINE.getValue().equals(param.getFrom())) {
            storeOrder.setIsChannel(OrderInfoEnum.PAY_CHANNEL_1.getValue());
        } else {
            storeOrder.setIsChannel(OrderInfoEnum.PAY_CHANNEL_0.getValue());
        }
        storeOrder.setUnique(key);
        storeOrder.setShippingType(Integer.valueOf(param.getShippingType()));
        /**
         门店有关
         if (OrderInfoEnum.SHIPPIING_TYPE_2.getValue().toString().equals(param.getShippingType())) {
         SystemStore systemStoreQueryVo = (SystemStore)this.systemStoreService.getById(param.getStoreId());
         if (systemStoreQueryVo == null) {
         throw new ErrorRequestException("暂无门店无法选择门店自提");
         }
         }
         storeOrder.setVerifyCode(StrUtil.sub(orderSn, orderSn.length(), -12)); //核销码
         storeOrder.setStoreId(systemStoreQueryVo.getId());//门店id 没写这
         */


        boolean res = this.save(storeOrder);
        if (!res) {
            throw new SystemException(AppHttpCodeEnum.NO_PARAMETE_OPERATE.getCode(), "订单生成失败");
        } else {
            /**
             * 门店有关
             if (computeVo.getUsedIntegral() > 0.0D) {
             this.decIntegral(userInfo, computeVo.getUsedIntegral(), computeVo.getDeductionPrice().doubleValue());
             }
             */
            /**
             * 优惠券有关
             if (computeVo.getCouponPrice().compareTo(BigDecimal.ZERO) > 0) {
             this.couponUserService.useCoupon(Integer.valueOf(param.getCouponId()));
             }
             */
            /*
            判断秒杀等的商品库存是否充足
            this.deStockIncSale(cartInfo);
            */

            this.orderCartInfoService.saveCartInfo(storeOrder.getId(), cartInfo);
            StoreCart cartObj = new StoreCart();
            cartObj.setIsPay(OrderInfoEnum.PAY_STATUS_1.getValue());
            LambdaQueryWrapper<StoreCart> wrapper = new LambdaQueryWrapper();
            wrapper.in(StoreCart::getId, cartIds);
            this.storeCartMapper.update(cartObj, wrapper);
            this.delCacheOrderInfo(uid, key);
            this.orderStatusService.create(storeOrder.getId(), OrderLogEnum.CREATE_ORDER.getValue(), OrderLogEnum.CREATE_ORDER.getDesc());
            String redisKey = String.valueOf(StrUtil.format("{}{}", new Object[]{"order:unpay:", storeOrder.getId()}));
            this.redisTemplate.opsForValue().set(redisKey, storeOrder.getOrderId(), 30L, TimeUnit.MINUTES);
            return storeOrder;
        }
    }

    /**
     * 计算订单金额，添加地址信息
     *
     * @param userInfo
     * @param key
     * @param couponId
     * @param useIntegral
     * @param shippingType
     * @param addressId
     * @return
     */
    @Override
    public ComputeVo computedOrder(ShopUser userInfo, String key, String couponId, String useIntegral, String shippingType, String addressId) {
        Long uid = userInfo.getUid();
        CacheDto cacheDTO = this.getCacheOrderInfo(uid, key);
        //去redis查询没有订单key, 订单过期
        if (ObjectUtil.isNull(cacheDTO)) {
            throw new SystemException(AppHttpCodeEnum.NO_PARAMETE_OPERATE.getCode(), "订单已过期,请刷新当前页面");
        } else {
            //用户支付的金额
            BigDecimal payPrice = cacheDTO.getPriceGroup().getTotalPrice();
            /**/
            UserAddress userAddress = null;
            if (StrUtil.isNotBlank(addressId)) {
                //获取地址信息
                userAddress = (UserAddress) this.userAddressService.getById(addressId);
            }
            PriceGroupDto priceGroup = this.getOrderPriceGroup(cacheDTO.getCartInfo(), userAddress);
            BigDecimal payPostage = priceGroup.getStorePostage();
            /* 配送方式 1=快递 ，2=门店自提*/
            Integer shippingTypeI = Integer.valueOf(shippingType);
            if (OrderInfoEnum.SHIPPIING_TYPE_1.getValue().equals(shippingTypeI)) {
                payPrice = NumberUtil.add(payPrice, payPostage);
            } else {
                payPostage = BigDecimal.ZERO;
            }
            /* 配送方式 1=快递 ，2=门店自提end*/
            Long combinationId = null;
            Long seckillId = null;
            Long bargainId = null;
            List<StoreCartQueryVo> cartInfo = cacheDTO.getCartInfo();

            /*砍价相关*/
             /*   StoreCartQueryVo cart;
                for (Iterator var18 = cartInfo.iterator(); var18.hasNext(); bargainId = cart.getBargainId()) {
                    cart = (StoreCartQueryVo) var18.next();
                    combinationId = cart.getCombinationId();
                    seckillId = cart.getSeckillId();
                }*/
            /*砍价相关end*/


            if (combinationId != null && combinationId > 0L || seckillId != null && seckillId > 0L || bargainId != null && bargainId > 0L) {
                couponId = "";
                useIntegral = "";
            }

            /*优惠劵相关*/
            BigDecimal couponPrice = BigDecimal.ZERO;
            /*if (StrUtil.isNotBlank(couponId) && !"0".equals(couponId)) {
                StoreCouponUser couponUser = this.couponUserService.getCoupon(Integer.valueOf(couponId), uid);
                if (couponUser == null) {
                    throw new EshopException("使用优惠劵失败");
                }

                if (couponUser.getUseMinPrice().compareTo(payPrice) > 0) {
                    throw new EshopException("不满足优惠劵的使用条件");
                }

                payPrice = NumberUtil.sub(payPrice, couponUser.getCouponPrice());
                couponPrice = couponUser.getCouponPrice();
            }*/
            /*优惠劵相关end*/


            BigDecimal deductionPrice = BigDecimal.ZERO;
            double usedIntegral = 0.0D;
            if (StrUtil.isNotBlank(useIntegral) && "1".equals(useIntegral) && userInfo.getIntegral().intValue() > 0) {
                Double integralMax = Double.valueOf(cacheDTO.getOther().getIntegralMax());
                BigDecimal integralFull = new BigDecimal(cacheDTO.getOther().getIntegralFull());
                Double integralRatio = Double.valueOf(cacheDTO.getOther().getIntegralRatio());
                if (cacheDTO.getPriceGroup().getTotalPrice().compareTo(integralFull) >= 0) {
                    Double userIntegral = userInfo.getIntegral().doubleValue();
                    if (integralMax.intValue() > 0 && Double.compare(userIntegral, integralMax) >= 0) {
                        userIntegral = integralMax;
                    }

                    deductionPrice = BigDecimal.valueOf(NumberUtil.mul(userIntegral, integralRatio));
                    if (deductionPrice.compareTo(payPrice) < 0) {
                        payPrice = NumberUtil.sub(payPrice, deductionPrice);
                        usedIntegral = userIntegral;
                    } else {
                        deductionPrice = payPrice;
                        payPrice = BigDecimal.ZERO;
                        usedIntegral = NumberUtil.round(NumberUtil.div(deductionPrice, BigDecimal.valueOf(integralRatio)), 2).doubleValue();
                    }
                }
            }

            if (payPrice.compareTo(BigDecimal.ZERO) <= 0) {
                payPrice = BigDecimal.ZERO;
            }
            return ComputeVo.builder()
                    .totalPrice(cacheDTO.getPriceGroup().getTotalPrice())
                    .payPrice(payPrice)
                    .payPostage(payPostage)
                    .couponPrice(couponPrice)
                    .deductionPrice(deductionPrice)
                    .usedIntegral(usedIntegral)
                    .payIntegral(cacheDTO.getPriceGroup().getPayIntegral())
                    .build();
        }
    }

    /**
     * 订单支付
     *
     * @param orderId
     * @param uid
     */
    @Override
    public void yuePay(String orderId, Long uid) {
        StoreOrderQueryVo orderInfo = this.getOrderInfo(orderId, uid);
        if (ObjectUtil.isNull(orderInfo)) {
            throw new SystemException(AppHttpCodeEnum.NO_PARAMETE_OPERATE.getCode(), "订单不存在");
        } else if (OrderInfoEnum.PAY_STATUS_1.getValue().equals(orderInfo.getPaid())) {
            throw new SystemException(AppHttpCodeEnum.NO_PARAMETE_OPERATE.getCode(), "该订单已支付");
        } else {

            ShopUser userInfo = userService.getById(uid);
            if (userInfo.getNowMoney().compareTo(orderInfo.getPayPrice()) < 0) {
                throw new SystemException(AppHttpCodeEnum.NO_PARAMETE_OPERATE.getCode(), "余额不足");
            } else {
                this.userService.decPrice(uid, orderInfo.getPayPrice());
                this.paySuccess(orderInfo.getOrderId(), PayTypeEnum.YUE.getValue());
            }
        }
    }

    @Override
    public Map<String, Object> orderListByPage(Long uid, int type, int page, int limit) {
        LambdaQueryWrapper<StoreOrder> wrapper = new LambdaQueryWrapper();
        if (uid != null) {
            wrapper.eq(StoreOrder::getUid, uid);
        } else {
            //用户ID为空，参数有误
            throw new SystemException(AppHttpCodeEnum.NO_PARAMETE_OPERATE, "用户ID为空");
        }
        wrapper.orderByDesc(StoreOrder::getId);

        switch (OrderStatusEnum.toType(type)) { //通过传入的参数返回被匹配的枚举
            case STATUS_0:
                wrapper.eq(StoreOrder::getPaid, OrderInfoEnum.PAY_STATUS_0.getValue()) //支付状态
                        .eq(StoreOrder::getRefundStatus, OrderInfoEnum.REFUND_STATUS_0.getValue()) //0 未退款 1 申请中 2 已退款
                        .eq(StoreOrder::getStatus, OrderInfoEnum.STATUS_0.getValue()); //订单状态（-1 : 申请退款 -2 : 退货成功 0：待发货；1：待收货；2：已收货；3：已完成；-1：已退款）
                break;
            case STATUS_1:
                wrapper.eq(StoreOrder::getPaid, OrderInfoEnum.PAY_STATUS_1.getValue())
                        .eq(StoreOrder::getRefundStatus, OrderInfoEnum.REFUND_STATUS_0.getValue())
                        .eq(StoreOrder::getStatus, OrderInfoEnum.STATUS_0.getValue());
                break;
            case STATUS_2:
                wrapper.eq(StoreOrder::getPaid, OrderInfoEnum.PAY_STATUS_1.getValue())
                        .eq(StoreOrder::getRefundStatus, OrderInfoEnum.REFUND_STATUS_0.getValue())
                        .eq(StoreOrder::getStatus, OrderInfoEnum.STATUS_1.getValue());
                break;
            case STATUS_3:
                wrapper.eq(StoreOrder::getPaid, OrderInfoEnum.PAY_STATUS_1.getValue())
                        .eq(StoreOrder::getRefundStatus, OrderInfoEnum.REFUND_STATUS_0.getValue())
                        .eq(StoreOrder::getStatus, OrderInfoEnum.STATUS_2.getValue());
                break;
            case STATUS_4:
                wrapper.eq(StoreOrder::getPaid, OrderInfoEnum.PAY_STATUS_1.getValue())
                        .eq(StoreOrder::getRefundStatus, OrderInfoEnum.REFUND_STATUS_0.getValue())
                        .eq(StoreOrder::getStatus, OrderInfoEnum.STATUS_3.getValue());
                break;
            case STATUS_MINUS_1:
                wrapper.eq(StoreOrder::getPaid, OrderInfoEnum.PAY_STATUS_1.getValue())
                        .eq(StoreOrder::getRefundStatus, OrderInfoEnum.REFUND_STATUS_1.getValue());
                break;
            case STATUS_MINUS_2:
                wrapper.eq(StoreOrder::getPaid, OrderInfoEnum.PAY_STATUS_0.getValue())
                        .eq(StoreOrder::getRefundStatus, OrderInfoEnum.REFUND_STATUS_2.getValue());
                break;
            case STATUS_MINUS_3:
                String[] strs = new String[]{"1", "2"};
                wrapper.eq(StoreOrder::getPaid, OrderInfoEnum.PAY_STATUS_1.getValue())
                        .in(StoreOrder::getRefundStatus, Arrays.asList(strs));
        }
        Page<StoreOrder> pageModel = new Page(page, limit);
        IPage<StoreOrder> pageList = this.yxStoreOrderMapper.selectPage(pageModel, wrapper); //查询出符合条件的订单列表
        List<StoreOrderQueryVo> list = BeanCopyUtils.copyBeanList(pageList.getRecords(), StoreOrderQueryVo.class);
        Map<String, Object> map = new LinkedHashMap(2);
        map.put("content", list.stream().map(this::handleOrder).collect(Collectors.toList()));
        map.put("totalElements", pageList.getTotal());
        return map;
    }

    @Override
    public StoreOrderQueryVo handleOrder(StoreOrderQueryVo order) {
        LambdaQueryWrapper<StoreOrderCartInfo> wrapper = new LambdaQueryWrapper();
        //获取订单下的购物车ID
        wrapper.eq(StoreOrderCartInfo::getOid, order.getId());
        //通过购物车ID去获取商品详情
        List<StoreOrderCartInfo> cartInfos = this.orderCartInfoService.list(wrapper);
        List<StoreCartQueryVo> cartInfo =
                cartInfos.stream()
                        .map(cart -> {
                            StoreCartQueryVo cartQueryVo = JSON.parseObject(cart.getCartInfo(), StoreCartQueryVo.class);//将订单表的购物车字符，反序列化成购物车对象
                            cartQueryVo.setUnique(cart.getUnique()); // 给购物车对象设置订单的唯一标识
                            //是否评价
                            // cartQueryVo.setIsReply(this.productReplyService.replyCount(cart.getUnique()));
                            return cartQueryVo;
                        }).collect(Collectors.toList());
        order.setCartInfo(cartInfo);
        //设置订单状态
        StatusDto statusDTO = new StatusDto();
        if (OrderStatusEnum.STATUS_0.getValue().equals(order.getPaid())) { //支付状态
            int offset = OrderConstants.YSHOP_ORDER_REDIS_TIME; //设置未付款订单过期时间
            Date time = DateUtil.offsetMinute(order.getCreateTime(), offset);//获取{offset} 分钟后的时间
            statusDTO.setClassfy("nobuy");
            statusDTO.setMsg(StrUtil.format("请在{}前完成支付", DateUtil.formatDateTime(time)));
            statusDTO.setType("0");
            statusDTO.setTitle("未支付");
        } else if (OrderInfoEnum.REFUND_STATUS_1.getValue().equals(order.getRefundStatus())) {
            statusDTO.setClassfy("state-sqtk");
            statusDTO.setMsg("商家审核中,请耐心等待");
            statusDTO.setType("-1");
            statusDTO.setTitle("申请退款中");
        } else if (OrderInfoEnum.REFUND_STATUS_2.getValue().equals(order.getRefundStatus())) {
            statusDTO.setClassfy("state-sqtk");
            statusDTO.setMsg("已为您退款,感谢您的支持");
            statusDTO.setType("-2");
            statusDTO.setTitle("已退款");
        } else if (OrderInfoEnum.STATUS_0.getValue().equals(order.getStatus())) { //未退款
            if (order.getPinkId() > 0L) {
              /*
              //拼团
              if (this.pinkService.pinkIngCount(order.getPinkId()) > 0) {
                    statusDTO.setClassfy("state-nfh");
                    statusDTO.setMsg("待其他人参加拼团");
                    statusDTO.setType("1");
                    statusDTO.setTitle("拼团中");
                } else {
                    statusDTO.setClassfy("state-nfh");
                    statusDTO.setMsg("商家未发货,请耐心等待");
                    statusDTO.setType("1");
                    statusDTO.setTitle("未发货");
                }*/
            } else if (OrderInfoEnum.SHIPPIING_TYPE_1.getValue().equals(order.getShippingType())) {
                statusDTO.setClassfy("state-nfh");
                statusDTO.setMsg("商家未发货,请耐心等待");
                statusDTO.setType("1");
                statusDTO.setTitle("未发货");
            } else {
                statusDTO.setClassfy("state-nfh");
                statusDTO.setMsg("待核销,请到核销点进行核销");
                statusDTO.setType("1");
                statusDTO.setTitle("待核销");
            }
        } else if (OrderInfoEnum.STATUS_1.getValue().equals(order.getStatus())) {
            statusDTO.setClassfy("state-ysh");
            statusDTO.setMsg("服务商已发货");
            statusDTO.setType("2");
            statusDTO.setTitle("待收货");
        } else if (OrderInfoEnum.STATUS_2.getValue().equals(order.getStatus())) {
            statusDTO.setClassfy("state-ypj");
            statusDTO.setMsg("已收货,快去评价一下吧");
            statusDTO.setType("3");
            statusDTO.setTitle("待评价");
        } else if (OrderInfoEnum.STATUS_3.getValue().equals(order.getStatus())) {
            statusDTO.setClassfy("state-ytk");
            statusDTO.setMsg("交易完成,感谢您的支持");
            statusDTO.setType("4");
            statusDTO.setTitle("交易完成");
        }
        if (PayTypeEnum.WEIXIN.getValue().equals(order.getPayType())) {
            statusDTO.setPayType("微信支付");
        } else if (PayTypeEnum.YUE.getValue().equals(order.getPayType())) {
            statusDTO.setPayType("余额支付");
        } else {
            statusDTO.setPayType("积分支付");
        }

        order.setStatusDto(statusDTO);
        return order;
    }

    /**
     * 获取订单统计数据
     *
     * @param uid
     * @return
     */
    public UserOrderCountVo orderData(Long uid) {
        LambdaQueryWrapper<StoreOrder> wrapperOne = new LambdaQueryWrapper();
        if (uid != null) {
            wrapperOne.eq(StoreOrder::getUid, uid);
        }

        wrapperOne.eq(StoreOrder::getRefundStatus, OrderInfoEnum.REFUND_STATUS_0.getValue()).eq(StoreOrder::getPaid, OrderInfoEnum.PAY_STATUS_1.getValue());
        Integer orderCount = Math.toIntExact(this.yxStoreOrderMapper.selectCount(wrapperOne));
        double sumPrice = this.yxStoreOrderMapper.sumPrice(uid);
        LambdaQueryWrapper<StoreOrder> wrapperTwo = new LambdaQueryWrapper();
        if (uid != null) {
            wrapperTwo.eq(StoreOrder::getUid, uid);
        }

        (wrapperTwo.eq(StoreOrder::getPaid, OrderInfoEnum.PAY_STATUS_0.getValue()).eq(StoreOrder::getRefundStatus, OrderInfoEnum.REFUND_STATUS_0.getValue())).eq(StoreOrder::getStatus, OrderInfoEnum.STATUS_0.getValue());
        Integer unpaidCount = Math.toIntExact(this.yxStoreOrderMapper.selectCount(wrapperTwo));
        LambdaQueryWrapper<StoreOrder> wrapperThree = new LambdaQueryWrapper();
        if (uid != null) {
            wrapperThree.eq(StoreOrder::getUid, uid);
        }

        wrapperThree.eq(StoreOrder::getPaid, OrderInfoEnum.PAY_STATUS_1.getValue()).eq(StoreOrder::getRefundStatus, OrderInfoEnum.REFUND_STATUS_0.getValue()).eq(StoreOrder::getStatus, OrderInfoEnum.STATUS_0.getValue());
        Integer unshippedCount = Math.toIntExact(this.yxStoreOrderMapper.selectCount(wrapperThree));
        LambdaQueryWrapper<StoreOrder> wrapperFour = new LambdaQueryWrapper();
        if (uid != null) {
            wrapperFour.eq(StoreOrder::getUid, uid);
        }

        (wrapperFour.eq(StoreOrder::getPaid, OrderInfoEnum.PAY_STATUS_1.getValue())).eq(StoreOrder::getRefundStatus, OrderInfoEnum.REFUND_STATUS_0.getValue()).eq(StoreOrder::getStatus, OrderInfoEnum.STATUS_1.getValue());
        Integer receivedCount = Math.toIntExact(this.yxStoreOrderMapper.selectCount(wrapperFour));
        LambdaQueryWrapper<StoreOrder> wrapperFive = new LambdaQueryWrapper();
        if (uid != null) {
            wrapperFive.eq(StoreOrder::getUid, uid);
        }

        (wrapperFive.eq(StoreOrder::getPaid, OrderInfoEnum.PAY_STATUS_1.getValue())).eq(StoreOrder::getRefundStatus, OrderInfoEnum.REFUND_STATUS_0.getValue()).eq(StoreOrder::getStatus, OrderInfoEnum.STATUS_2.getValue());
        Integer evaluatedCount = Math.toIntExact(this.yxStoreOrderMapper.selectCount(wrapperFive));
        LambdaQueryWrapper<StoreOrder> wrapperSix = new LambdaQueryWrapper();
        if (uid != null) {
            wrapperSix.eq(StoreOrder::getUid, uid);
        }

        (wrapperSix.eq(StoreOrder::getPaid, OrderInfoEnum.PAY_STATUS_1.getValue())).eq(StoreOrder::getRefundStatus, OrderInfoEnum.REFUND_STATUS_0.getValue()).eq(StoreOrder::getStatus, OrderInfoEnum.STATUS_3.getValue());
        Integer completeCount = Math.toIntExact(this.yxStoreOrderMapper.selectCount(wrapperSix));
        LambdaQueryWrapper<StoreOrder> wrapperSeven = new LambdaQueryWrapper();
        if (uid != null) {
            wrapperSeven.eq(StoreOrder::getUid, uid);
        }

        String[] strArr = new String[]{"1", "2"};
        wrapperSeven.eq(StoreOrder::getPaid, OrderInfoEnum.PAY_STATUS_1.getValue()).in(StoreOrder::getRefundStatus, Arrays.asList(strArr));
        Integer refundCount = Math.toIntExact(this.yxStoreOrderMapper.selectCount(wrapperSeven));
        return UserOrderCountVo.builder().orderCount(orderCount).sumPrice(sumPrice).unpaidCount(unpaidCount).unshippedCount(unshippedCount).receivedCount(receivedCount).evaluatedCount(evaluatedCount).completeCount(completeCount).refundCount(refundCount).build();
    }

    @Override
    public void cancelOrder(String orderId, Long uid) {
        StoreOrderQueryVo order = this.getOrderInfo(orderId, uid);
        if (ObjectUtil.isNull(order)) {
            throw new SystemException(AppHttpCodeEnum.NO_PARAMETE_OPERATE.getCode(), "订单不存在");
        } else {
            this.regressionIntegral(order, 0);
            this.regressionStock(order, 0);
            this.regressionCoupon(order, 0);
            this.yxStoreOrderMapper.deleteById(order.getId());
        }
    }

    private void regressionCoupon(StoreOrderQueryVo order, Integer type) {
        if (type == 0) {
            if (OrderInfoEnum.PAY_STATUS_1.getValue().equals(order.getPaid()) || OrderStatusEnum.STATUS_MINUS_2.getValue().equals(order.getStatus())) {
                return;
            }
        } else if (!OrderInfoEnum.PAY_STATUS_1.getValue().equals(order.getPaid()) || !OrderInfoEnum.REFUND_STATUS_2.getValue().equals(order.getRefundStatus())) {
            return;
        }

        if (order.getCouponId() != null && order.getCouponId() > 0) {
            //查找优惠券
//            StoreCouponUser couponUser = (StoreCouponUser)this.couponUserService.getOne((Wrapper)((LambdaQueryWrapper)((LambdaQueryWrapper) Wrappers.lambdaQuery().eq(StoreCouponUser::getId, order.getCouponId())).eq(StoreCouponUser::getStatus, CouponEnum.STATUS_1.getValue())).eq(StoreCouponUser::getUid, order.getUid()));
           /* if (ObjectUtil.isNotNull(couponUser)) {
                StoreCouponUser storeCouponUser = new StoreCouponUser();
                storeCouponUser.setStatus(CouponEnum.STATUS_0.getValue());
                storeCouponUser.setUseTime((Date)null);
                this.couponUserService.update(storeCouponUser, (Wrapper)((LambdaQueryWrapper)Wrappers.lambdaQuery().eq(StoreCouponUser::getId, order.getCouponId())).eq(StoreCouponUser::getUid, order.getUid()));
            }*/
        }

    }

    @Override
    public void removeOrder(String orderId, Long uid) {
        StoreOrderQueryVo order = this.getOrderInfo(orderId, uid);
        if (order == null) {
            throw new SystemException(AppHttpCodeEnum.NO_PARAMETE_OPERATE, "订单不存在");
        } else {
            order = this.handleOrder(order);
            if (!OrderInfoEnum.STATUS_3.getValue().equals(order.getStatus())) {
                //订单未完成，不能删除
                throw new SystemException(AppHttpCodeEnum.FAIL, "该订单无法删除");
            } else {
                this.yxStoreOrderMapper.deleteById(order.getId());
                //记录下操作
                this.orderStatusService.create(order.getId(), OrderLogEnum.REMOVE_ORDER.getValue(), OrderLogEnum.REMOVE_ORDER.getDesc());
            }
        }
    }

    private void regressionStock(StoreOrderQueryVo order, Integer type) {
        if (type == 0) {
            if (OrderInfoEnum.PAY_STATUS_1.getValue().equals(order.getPaid()) || OrderStatusEnum.STATUS_MINUS_2.getValue().equals(order.getStatus())) {
                return;
            }
        } else if (!OrderInfoEnum.PAY_STATUS_1.getValue().equals(order.getPaid()) || !OrderInfoEnum.REFUND_STATUS_2.getValue().equals(order.getRefundStatus())) {
            return;
        }

        LambdaQueryWrapper<StoreOrderCartInfo> wrapper = new LambdaQueryWrapper();
        wrapper.in(StoreOrderCartInfo::getCartId, Arrays.asList(order.getCartId().split(",")));
        List<StoreOrderCartInfo> cartInfoList = this.orderCartInfoService.list(wrapper);
        Iterator var5 = cartInfoList.iterator();

        while (true) {
            while (var5.hasNext()) {
                StoreOrderCartInfo cartInfo = (StoreOrderCartInfo) var5.next();
                StoreCartQueryVo cart = (StoreCartQueryVo) JSONObject.parseObject(cartInfo.getCartInfo(), StoreCartQueryVo.class);
                if (order.getCombinationId() != null && order.getCombinationId() > 0L) {
                    this.productService.incProductStock(cart.getCartNum(), cart.getProductId(), cart.getProductAttrUnique(), order.getCombinationId(), ProductTypeEnum.COMBINATION.getValue());
                } else if (order.getSeckillId() != null && order.getSeckillId() > 0L) {
                    this.productService.incProductStock(cart.getCartNum(), cart.getProductId(), cart.getProductAttrUnique(), order.getSeckillId(), ProductTypeEnum.SECKILL.getValue());
                } else if (order.getBargainId() != null && order.getBargainId() > 0L) {
                    //商品砍价
                    //this.storeBargainService.incStockDecSales(cart.getCartNum(), order.getBargainId());
                } else {
                    this.productService.incProductStock(cart.getCartNum(), cart.getProductId(), cart.getProductAttrUnique(), 0L, (String) null);
                }
            }

            return;
        }
    }

    private void regressionIntegral(StoreOrderQueryVo order, Integer type) {
        if (type == 0) {
            if (OrderInfoEnum.PAY_STATUS_1.getValue().equals(order.getPaid()) || OrderStatusEnum.STATUS_MINUS_2.getValue().equals(order.getStatus())) {
                return;
            }
        } else if (!OrderInfoEnum.PAY_STATUS_1.getValue().equals(order.getPaid()) || !OrderInfoEnum.REFUND_STATUS_2.getValue().equals(order.getRefundStatus())) {
            return;
        }

        if (order.getPayIntegral().compareTo(BigDecimal.ZERO) > 0) {
            order.setUseIntegral(order.getPayIntegral());
        }

        if (order.getUseIntegral().compareTo(BigDecimal.ZERO) > 0) {
            if (OrderStatusEnum.STATUS_MINUS_2.getValue().equals(order.getStatus()) || OrderInfoEnum.REFUND_STATUS_2.getValue().equals(order.getRefundStatus()) || order.getBackIntegral().compareTo(BigDecimal.ZERO) <= 0) {
                ShopUser shopUser = (ShopUser) this.userService.getById(order.getUid());
                BigDecimal newIntegral = NumberUtil.add(order.getUseIntegral(), shopUser.getIntegral());
                shopUser.setIntegral(newIntegral);
                this.userService.updateById(shopUser);
                this.billService.income(shopUser.getUid(), "积分回退", BillDetailEnum.CATEGORY_2.getValue(), BillDetailEnum.TYPE_8.getValue(), order.getUseIntegral().doubleValue(), newIntegral.doubleValue(), "购买商品失败,回退积分" + order.getUseIntegral(), order.getId().toString());
                StoreOrder storeOrder = new StoreOrder();
                storeOrder.setBackIntegral(order.getUseIntegral());
                storeOrder.setId(order.getId());
                this.yxStoreOrderMapper.updateById(storeOrder);
            }
        }
    }

    public void paySuccess(String orderId, String payType) {
        StoreOrderQueryVo orderInfo = this.getOrderInfo(orderId, (Long) null);
        LambdaQueryWrapper<StoreOrder> wrapper = new LambdaQueryWrapper();
        wrapper.eq(StoreOrder::getOrderId, orderId);
        StoreOrder storeOrder = new StoreOrder();
        storeOrder.setPaid(OrderInfoEnum.PAY_STATUS_1.getValue());
        storeOrder.setPayType(payType);
        storeOrder.setPayTime(new Date());
        this.yxStoreOrderMapper.update(storeOrder, wrapper);
        this.userService.incPayCount(orderInfo.getUid());
        this.orderStatusService.create(orderInfo.getId(), OrderLogEnum.PAY_ORDER_SUCCESS.getValue(), OrderLogEnum.PAY_ORDER_SUCCESS.getDesc());
        /**
         * 拼团产品
         if (orderInfo.getCombinationId() > 0L) {
         this.pinkService.createPink(orderInfo);
         }
         */
        /**
         * 砍价
         if (orderInfo.getBargainId() > 0L) {
         this.storeBargainUserService.setBargainUserStatus(orderInfo.getBargainId(), orderInfo.getUid());
         }
         */
        ShopUser userInfo = this.userService.getById(orderInfo.getUid());
        String payTypeMsg = PayTypeEnum.WEIXIN.getDesc();
        if (PayTypeEnum.YUE.getValue().equals(payType)) {
            payTypeMsg = PayTypeEnum.YUE.getDesc();
        }

        this.billService.expend(userInfo.getUid(), "购买商品", BillDetailEnum.CATEGORY_1.getValue(), BillDetailEnum.TYPE_3.getValue(), orderInfo.getPayPrice().doubleValue(), userInfo.getNowMoney().doubleValue(), payTypeMsg + orderInfo.getPayPrice() + "元购买商品");
        TemplateBean templateBean = TemplateBean.builder()
                .orderId(orderInfo.getOrderId())
                .price(orderInfo.getPayPrice().toString())
                .uid(orderInfo.getUid())
                .templateType(TemplateListenEnum.TYPE_1.getValue()).build();
        //调用了org.springframework.context 的方法，不知道干啥
        this.publisher.publishEvent(new TemplateEvent(this, templateBean));
    }

    private CacheDto getCacheOrderInfo(Long uid, String key) {
        Object obj = this.redisUtils.get("yshop:order" + uid + key);
        return obj == null ? null : JSON.parseObject(obj.toString(), CacheDto.class);
    }

    /**
     * 计算订单总价
     *
     * @param cartInfo
     * @param userAddress
     * @return
     */
    private PriceGroupDto getOrderPriceGroup(List<StoreCartQueryVo> cartInfo, UserAddress userAddress) {
        BigDecimal storePostage = BigDecimal.ZERO;
        String storeFreePostageStr = this.systemConfigService.getData("store_free_postage");
        BigDecimal storeFreePostage = BigDecimal.ZERO;
        if (NumberUtil.isNumber(storeFreePostageStr) && StrUtil.isNotBlank(storeFreePostageStr)) {
            storeFreePostage = new BigDecimal(storeFreePostageStr);
        }

        BigDecimal totalPrice = this.getOrderSumPrice(cartInfo, "truePrice");
        BigDecimal costPrice = this.getOrderSumPrice(cartInfo, "costPrice");
        BigDecimal vipPrice = this.getOrderSumPrice(cartInfo, "vipTruePrice");
        BigDecimal payIntegral = this.getOrderSumPrice(cartInfo, "payIntegral");
      /*  if (storeFreePostage.compareTo(BigDecimal.ZERO) != 0 && totalPrice.compareTo(storeFreePostage) <= 0) {
            storePostage = this.handlePostage(cartInfo, userAddress);
        }*/

        if (cartInfo.size() == 1 && ((StoreCartQueryVo) cartInfo.get(0)).getProductInfo().getIsIntegral() != null && ((StoreCartQueryVo) cartInfo.get(0)).getProductInfo().getIsIntegral() == 1) {
            totalPrice = BigDecimal.ZERO;
        }

        PriceGroupDto priceGroupDTO = new PriceGroupDto();
        priceGroupDTO.setStorePostage(storePostage);
        priceGroupDTO.setStoreFreePostage(storeFreePostage);
        priceGroupDTO.setTotalPrice(totalPrice);
        priceGroupDTO.setCostPrice(costPrice);
        priceGroupDTO.setVipPrice(vipPrice);
        priceGroupDTO.setPayIntegral(payIntegral);
        return priceGroupDTO;
    }

    private BigDecimal getOrderSumPrice(List<StoreCartQueryVo> cartInfo, String key) {
        BigDecimal sumPrice = BigDecimal.ZERO;
        Iterator var4;
        StoreCartQueryVo storeCart;
        if ("truePrice".equals(key)) {
            for (var4 = cartInfo.iterator(); var4.hasNext(); sumPrice = NumberUtil.add(sumPrice, NumberUtil.mul(storeCart.getCartNum(), storeCart.getTruePrice()))) {
                storeCart = (StoreCartQueryVo) var4.next();
            }
        } else if ("costPrice".equals(key)) {
            for (var4 = cartInfo.iterator(); var4.hasNext(); sumPrice = NumberUtil.add(sumPrice, NumberUtil.mul(storeCart.getCartNum(), storeCart.getCostPrice()))) {
                storeCart = (StoreCartQueryVo) var4.next();
            }
        } else if ("vipTruePrice".equals(key)) {
            for (var4 = cartInfo.iterator(); var4.hasNext(); sumPrice = NumberUtil.add(sumPrice, NumberUtil.mul(storeCart.getCartNum(), storeCart.getVipTruePrice()))) {
                storeCart = (StoreCartQueryVo) var4.next();
            }
        } else if ("payIntegral".equals(key)) {
            for (var4 = cartInfo.iterator(); var4.hasNext(); sumPrice = NumberUtil.add(sumPrice, NumberUtil.mul(storeCart.getCartNum(), storeCart.getProductInfo().getAttrInfo().getIntegral()))) {
                storeCart = (StoreCartQueryVo) var4.next();
            }
        }

        return sumPrice;
    }

    private BigDecimal getGainIntegral(List<StoreCartQueryVo> cartInfo) {
        BigDecimal gainIntegral = BigDecimal.ZERO;

        for (StoreCartQueryVo cart : cartInfo) {
            if (cart.getCombinationId() <= 0L && cart.getSeckillId() <= 0L && cart.getBargainId() <= 0L) {
                BigDecimal cartInfoGainIntegral = BigDecimal.ZERO;
                Double gain = 0.0D;
                if (cart.getProductInfo().getGiveIntegral() != null) {
                    gain = cart.getProductInfo().getGiveIntegral().doubleValue();
                }
                if (gain > 0.0D) {
                    cartInfoGainIntegral = NumberUtil.round(NumberUtil.mul(cart.getCartNum(), gain), 2);
                }

                gainIntegral = NumberUtil.add(gainIntegral, cartInfoGainIntegral);
            }
        }

        return gainIntegral;
    }

    /**
     * 从redis删除订单
     *
     * @param uid
     * @param key
     */
    private void delCacheOrderInfo(Long uid, String key) {
        this.redisUtils.del(new String[]{"yshop:order" + uid + key});
    }

    /*
    判断秒杀等的商品库存是否充足
    public void deStockIncSale(List<StoreCartQueryVo> cartInfo) {
        Iterator var2 = cartInfo.iterator();

        while(true) {
            while(var2.hasNext()) {
                StoreCartQueryVo storeCartVO = (StoreCartQueryVo)var2.next();
                Long combinationId = storeCartVO.getCombinationId();
                Long seckillId = storeCartVO.getSeckillId();
                Long bargainId = storeCartVO.getBargainId();
                if (combinationId != null && combinationId > 0L) {
                    this.productService.decProductStock(storeCartVO.getCartNum(), storeCartVO.getProductId(), storeCartVO.getProductAttrUnique(), combinationId, ProductTypeEnum.COMBINATION.getValue());
                } else if (seckillId != null && seckillId > 0L) {
                    this.productService.decProductStock(storeCartVO.getCartNum(), storeCartVO.getProductId(), storeCartVO.getProductAttrUnique(), seckillId, ProductTypeEnum.SECKILL.getValue());
                } else if (bargainId != null && bargainId > 0L) {
                    this.storeBargainService.decStockIncSales(storeCartVO.getCartNum(), bargainId);
                } else {
                    this.productService.decProductStock(storeCartVO.getCartNum(), storeCartVO.getProductId(), storeCartVO.getProductAttrUnique(), 0L, "");
                }
            }

            return;
        }
    }
     */
    /*生成订单的KEY*/
    private String cacheOrderInfo(Long uid, List<StoreCartQueryVo> cartInfo, PriceGroupDto priceGroup, OtherDto other) {
        String key = IdUtil.simpleUUID();
        CacheDto cacheDTO = new CacheDto();
        cacheDTO.setCartInfo(cartInfo);
        cacheDTO.setPriceGroup(priceGroup);
        cacheDTO.setOther(other);
        this.redisUtils.set("yshop:order" + uid + key, JSON.toJSONString(cacheDTO), 600L); //redis缓存，保存订单的信息
//        String o = (String) this.redisUtils.get("yshop:order" + uid + key);
        return key;
    }
}

